package ldh.text.service;

import java.io.*;
import java.nio.CharBuffer;

public class CharDataService implements DataService<CharBuffer> {

    private File file;

    public CharDataService(File file) throws IOException {
        this.file = file;
    }

    @Override
    public long dataSize() {
        throw new RuntimeException("不支持者个方法");
    }

    @Override
    public CharBuffer loadData(long position, int size) throws IOException {
        try(FileReader fileReader = new FileReader(file);
            BufferedReader bufferedReader = new BufferedReader(fileReader);) {
            bufferedReader.skip(position);
            CharBuffer charBuffer = CharBuffer.allocate(size);
            bufferedReader.read(charBuffer);
            charBuffer.flip();
            return charBuffer;
        }
    }

    @Override
    public void saveData(String file, byte[] data, int startPosition, int endPosition) {

    }

    @Override
    public void saveData(File file, byte[] data) throws IOException {

    }
}
